package com.yang.controller.wx;

import com.fasterxml.jackson.databind.ser.Serializers;
import com.yang.bean.MarketAddress;
import com.yang.bean.MarketUser;
import com.yang.bean.common.BaseRespVo;
import com.yang.bean.common.CommonData;
import com.yang.bean.fxy.bo.AddressDeleteBo;
import com.yang.service.wx.WXAddressService;
import com.yang.utils.UserUtil;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName WXAddressController
 * @Description:
 * @Author TrueEnd
 * @Date 2022/9/11
 * @Version
 **/
@RestController
@RequestMapping("wx/address")
public class WXAddressController {

    @Autowired
    WXAddressService wxAddressService;

    @Autowired
    DefaultWebSessionManager defaultWebSessionManager;

    @RequestMapping("list")
    public BaseRespVo addressList(HttpServletRequest request) {
        MarketUser userMsg = UserUtil.getUserMsg(request, defaultWebSessionManager);

        CommonData<MarketAddress> data = wxAddressService.addressList(userMsg.getId());
        return BaseRespVo.ok(data);
    }

    @RequestMapping("detail")
    public BaseRespVo addressDetail(Integer id) {
        MarketAddress data = wxAddressService.addressDetail(id);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("save")
    public BaseRespVo addressSave(@RequestBody MarketAddress marketAddress,HttpServletRequest request) {
        MarketUser userMsg = UserUtil.getUserMsg(request, defaultWebSessionManager);
        wxAddressService.addressSave(marketAddress,userMsg.getId());
        return BaseRespVo.ok(marketAddress.getId());
    }

    @RequestMapping("delete")
    public BaseRespVo addressDelete(@RequestBody AddressDeleteBo addressDeleteBo) {
        wxAddressService.addressDelete(addressDeleteBo.getId());
        return BaseRespVo.ok();
    }
}
